package com.chenhongjian.webapp.utils;

import com.alibaba.fastjson.JSONObject;

/**
 * Created by a on 2017/11/11.
 */
public class SmsCodeUtils {
    public static String sendMessage(String phone) {
        String url = "http://smssh1.253.com/msg/send/json";
        String password = "95gPJ1MLGN2647";
        String user = "CN7244251";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("account", user);
        jsonObject.put("phone",phone);
        jsonObject.put("password", password);
        int code = (int) ((Math.random() * 9 + 1) * 1000);
        jsonObject.put("msg", "【美哇精选】您的登录验证码是：" + code);
        String response = SmsUtils.sendSmsByPost(url, jsonObject.toJSONString());
        JSONObject object =  JSONObject.parseObject(response);
        if (object != null && object.getIntValue("code")== 0){
                return String.valueOf(code);
        }
        return null;
    }

}
